const mongoose = require('mongoose')
const {dbUri} = require('../config/config.default')
mongoose.connect(dbUri,{
    useNewUrlParser:true,
    useUnifiedTopology:true,
})

const db = mongoose.connection

db.on('err',console.error.bind(console,'数据库连接失败:'))

db.once('open',()=>{
    console.log('MongoDB 数据库连接成功');
})

// 创建数据模型
// const Cat = mongoose.model('Cat',{name:String})

// const Kitty = new Cat({name:'Tom'})
// Kitty.save().then(()=>console.log('保存成功'))

// 组织导出模型类
module.exports = {
    User:mongoose.model('User',require('./user')),
    Room:mongoose.model('Room',require('./room'))
}